package com.ssyt.wxstore.sys.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.ssyt.wxstore.common.BaseDao;
import com.ssyt.wxstore.sys.entity.SysMenu;

@Repository
public class MenuDao extends BaseDao<SysMenu, String> {
	/**
	 * 获取菜单列表
	 * 
	 * @param id
	 * @return
	 */
	public List<SysMenu> getMenuList(String id) {
		StringBuffer sb = new StringBuffer();
		sb.append("SELECT sm.id,sm.text,sm.pid,sm.url,sm.state ");
		sb.append("FROM sys_role sr,sys_menu sm,sys_role_menu srm,sys_user su,sys_user_role sur ");
		sb.append("WHERE sr.id=srm.sys_role_id AND sm.id=srm.sys_menu_id AND su.id=sur.sys_user_id AND sr.id=sur.sys_role_id ");
		sb.append("AND sr.state=1 AND su.id=?");
		return listEntityBySql(sb.toString(), id);
	}

	/**
	 * 获取所有菜单
	 * 
	 * @param id
	 * 
	 * @return
	 */
	public List<SysMenu> getMenu(String id) {
		return listEntityBySql("SELECT * FROM sys_menu sm where sm.pid=?", id);
	}

}
